
#pragma comment(lib,"user32.lib")

#include <iostream>
#include"../mem_op2/mem_util.h"

using namespace std;


int main()
{
    cout << "Hello World!" << endl;

//    MessageBox(NULL,L"AAAAA",L"BBBBB",MB_OK);
    cout << MessageBoxA << endl;

    xy::File f(L"D:\\programming\\C++\\mem_ops\\callmessagebox");

    cout << f.size() << endl;

    unsigned char code[1024] = {0};

    cout << "read code size: " << f.read(code,f.size()) << endl;

    for(int i=0;i<sizeof (code);i++){
        cout << "0x" << hex << (int)code[i]<<',';
    }
    cout << endl;

    DWORD pid = -1;
    cout << "process id: ";
    cin>>pid;
    cout << endl;
    xy::OtherProcess p(pid);
    xy::OtherProcessMemory pm(&p);

    LPVOID addr = pm.alloc(sizeof(code));
    cout << "write code size: " << pm.write(addr,code,sizeof (code)) <<endl;
    xy::RemoteThread t(&p,LPTHREAD_START_ROUTINE(addr));
    t.start();
    t.wait();
    unsigned char d[sizeof (code)];

    cout << "read code size: " << pm.read(addr,d,sizeof (d)) << endl;
    for(int i=0;i<sizeof (d);i++){
        cout << "0x" << hex << (int)d[i]<<',';
    }
    cout << endl;
    pm.free(addr);

    cout << "Over!" << endl;

    return 0;
}
